﻿using AutoMapper;
using B.S.Material.Domain.BOM;
using B.S.Material.ErrorCode;
using B.S.Material.Read.Api.Applications.Command.MaterialsPickingDetailCommand;
using MediatR;
using SqlSugar;

namespace B.S.Material.Read.Api.Applications.Handler.MaterialsPickingDetailHandelr
{
    public class GetMaterialsPickingDetailHandelr : IRequestHandler<GetMaterialsPickingDetailCommand, ApiResult<List<MaterialsPickingDetail>>>
    {

        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public GetMaterialsPickingDetailHandelr(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<List<MaterialsPickingDetail>>> Handle(GetMaterialsPickingDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MaterialsPickingDetail>> result = new ApiResult<List<MaterialsPickingDetail>>();

            var list = await db.Queryable<MaterialsPickingDetail>().ToListAsync();
            result.data = list;
            if (result.data != null)
            {
                result.Code = ApiEnum.显示成功;
                result.MAG = ApiEnum.显示成功.ToString();
            }
            else
            {
                result.Code = ApiEnum.显示成功;
                result.MAG = ApiEnum.显示成功.ToString();
            }

            return result;
        }
    }
}
